package org.example.likou150.tree;

// https://leetcode.cn/problems/count-complete-tree-nodes/?envType=study-plan-v2&envId=top-interview-150
public class CountNodes {

    private int index = 0;
    public int countNodes(TreeNode root) {
        if(root==null){
            return 0;
        }
        index++;
        countNodes(root.left);
        countNodes(root.right);
        return index;
    }


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
